package leetcode;

import java.util.Arrays;
import java.util.HashSet;

/**
 * @Project : AlgorithmLearning
 * @Package : Leetcode
 * @File : Q0349.java
 * @Author : WangRuoyu
 * @Date 2023/11/8 11:04
 */


public class Q0349 {
    public int[] intersection(int[] nums1, int[] nums2) {
        HashSet<Integer> set = new HashSet<>();
        HashSet<Integer> resset = new HashSet<>();
        for (int i = 0; i < nums1.length; i++) {
            set.add(nums1[i]);
        }
        for (int i = 0; i < nums2.length; i++) {
            if (set.contains(nums2[i])) resset.add(nums2[i]);
        }
        int[] res = new int[resset.size()];
        int i = 0;
        for (Integer val : resset) {
            res[i++] = val;
        }
        return res;
    }

    public static void main(String[] args) {
        Q0349 sl = new Q0349();
        int[] nums1 = {4, 9, 5};
        int[] nums2 = {9, 4, 9, 8, 4};
        System.out.println(Arrays.toString(sl.intersection(nums1, nums2)));
    }
}